package com.tanhua.server.interceptor;

import com.tanhua.domain.db.User;

public class UserHolder {
    private static ThreadLocal<User> tl = new ThreadLocal();

    /**
     * 把User对象绑定到当前线程
     * @param user user对象
     */
    public static void setUser(User user){
        tl.set(user);
    }

    /**
     * 从当前线程上获取绑定的User对象
     */
    public static User getUser(){
        return tl.get();
    }

    /**
     * 从当前线程上获取绑定的User对象的id
     */
    public static Long getUserId(){
        return tl.get().getId();
    }
}
